<!--业务审批modal-->
<template>
  <c-modal
      :width="width"
      :visible="visible"
      :title="title"
      :top="20"
      :bottom="20"
      @cancel="cancel"
  >
    <Spin size="large" fix v-if="Loading"></Spin>
    <Tabs v-model="tabName" id="Tab">
      <Tab-pane label="任务处理" name="name1">
        <div class="overflowContent" :key="key">
          <!--申请-->
          <div v-if="ssca0016=='100'">
            <application-apply-update ref="application" v-if="approvemodal=='update'"/>
            <application-apply-view ref="application" :validateCode.sync="validateCode"
                                    :validateMsg.sync="validateMsg" v-if="approvemodal=='view'"/>
          </div>
          <!--变更-->
          <div v-else>
            <application-change-update ref="application" v-if="approvemodal=='update'"/>
            <application-change-view ref="application" :validateCode.sync="validateCode"
                                     :validateMsg.sync="validateMsg" v-if="approvemodal=='view'"/>
          </div>
          <div id="inforDiv" :key="key">
            <Divider orientation="left">审批意见</Divider>
            <handle0 ref="handle" v-if="handleNum==0"/>
            <handle01 ref="handle" v-if="handleNum==1"/>
            <handle02 ref="handle" v-if="handleNum==2"/>
            <handle03 ref="handle" v-if="handleNum==3"/>
            <handle04 ref="handle" v-if="handleNum==4" @lockAllButton="lockAllButton"
                      @setButtonHidden="setButtonHidden"/>
            <handle05 ref="handle" v-if="handleNum==5" @changeButton="changeButton"
                      @lockAllButton="lockAllButton"
                      @setButtonHidden="setButtonHidden"/>
            <handle06 ref="handle" v-if="handleNum==6"/>
          </div>
        </div>
        <div id="examinationButtonDiv" :style="buttonHidden">
          <template v-for="item in buttonList">
            <Button type="primary" style="margin-left: 20px" :value="item"
                    :key="item.status"
                    @click="operation(item)" v-if="item.hidden=='0'"
                    :loading="btnLoading"
                    :disabled="item.disable=='1'?true:false">
              {{ item.name }}
            </Button>
          </template>
        </div>
      </Tab-pane>
      <Tab-pane label="审批意见" name="name2">
        <div class="overflowContent" :key="key">
          <opinions ref="opinions"/>
        </div>
      </Tab-pane>
      <Tab-pane label="流程图" name="name3">
        <div class="overflowContent" :key="key">
          <application-image ref="img"/>
        </div>
      </Tab-pane>
      <Tab-pane label="核对结果" name="name4">
        <div class="overflowContent" :key="key">
          <application-hd-result ref="applicationHdResult"/>
        </div>
      </Tab-pane>
    </Tabs>
    <div slot="footer">
    </div>
  </c-modal>
</template>

<script>
import applicationApplyView from './application_apply_view';
import applicationApplyUpdate from './application_apply_update';
import applicationChangeView from './application_change_view';
import applicationChangeUpdate from './application_change_update';
import handle0 from './modules/process_handle0'
import handle01 from './modules/process_handle01'
import handle02 from './modules/process_handle02'
import handle03 from './modules/process_handle03'
import handle04 from './modules/process_handle04'
import handle05 from './modules/process_handle05'
import handle06 from './modules/process_handle06'
import applicationImage from './applicationImage'
import {postAction} from '@/api/request'
import opinions from './applicationOpinions'
import applicationHdResult from './applicationHdResult'

export default {
  name: "application-modal",
  components: {
    applicationApplyView,
    applicationApplyUpdate,
    applicationChangeView,
    applicationChangeUpdate,
    handle0,
    handle01,
    handle02,
    handle03,
    handle04,
    handle05,
    handle06,
    applicationImage,
    opinions,
    applicationHdResult,
  },

  data() {
    return {
      approvemodal: 'view',
      validateCode: true, //第十步附件 验证code： true(验证通过)  false(验证失败)
      validateMsg: '',//第十步附件验证失败提示信息
      tabName: "name1",
      handleNum: 99,
      scrollable: true,
      title: "审批详情",
      visible: false,
      disableSubmit: false,
      width: 800,
      height: 400,
      model: {},
      familyInfo: {},
      ss12001Id: "",
      oldButtonList: [],
      buttonList: [],
      key: "",
      Loading: false,
      btnLoading: false,
      ssca0016: "",
      buttonHidden: "display:block"
    }
  },
  watch: {
    validateCode(newvalue, oldvalue) {
      this.validateCode = newvalue
    },
    validateMsg(newvalue, oldvalue) {
      this.validateMsg = newvalue
    }
  },
  methods: {
    edit(record) {
      this.ss12001Id = record.ss12001Id;
      this.tabName = "name1";
      this.visible = true;
      this.familyInfo = record;
      this.approvemodal = record.approvemodal;
      this.assistancetype = record.assistancetype;
      this.ssca0016 = record.ssca0016;
      this.handleNum = record.busmodal;
      this.getApproveBtnMapList(record.processinstid, record.ss12001Id);
      //获取审批按钮信息
      this.$nextTick(() => {
        this.$refs.application.edit(record);
        this.$refs.img.edit(record, this.key);
        this.$refs.opinions.edit(record);
        this.$refs.applicationHdResult.edit(record);
      });
      this.validateCode = true;
      //ext_act_node_config checkfile为受理阶段：必填要件
      // if (record.checkfile === '1') {
      //   this.getApplication10Info();
      // }
    },
    getApplication10Info(infor, e) {
      //不是申请，都走17
      if (this.ssca0016 != '100') {
        postAction("/api/ac/subsistence/ss17010Service/check",
            {
              familyId: this.familyInfo.ssca0001,
              ss12001Id: this.familyInfo.ss12001Id
              , processStage: this.familyInfo.processstage
              , assistanceType: this.assistanceType
            }).then((res) => {
          if (res.data.errcode != 0) {
            this.$Message.error(res.data.errmsg);
            return  false;
          } else {
            this.buzTaskComplete(infor, e);
          }
        })
      } else {
        postAction("/api/ac/subsistence/ss11010Service/check",
            {
              familyId: this.familyInfo.ssca0001,
              ss12001Id: this.familyInfo.ss12001Id
              , processStage: this.familyInfo.processstage
              , assistanceType: this.assistanceType
            }).then((res) => {
          if (res.data.errcode != 0) {
            this.$Message.error(res.data.errmsg);
            return  false;
          } else {
            this.buzTaskComplete(infor, e);
          }
        })
      }
    },
    getApproveBtnMapList(processinstid, ss12001Id) {
      postAction("/api/ac/subsistence/ss00000Service/getApproveBtnMapList", {
        processinstid: processinstid,
        ss12001Id: ss12001Id
      }).then((res) => {
        if (res.data.errcode == 0) {
          this.buttonList = JSON.parse(JSON.stringify(res.data.data));
          this.oldButtonList = JSON.parse(JSON.stringify(res.data.data));
        }
      })
    },
    operation(e) {
      if (e.userids) {
        var that = this;
        var title = "确定进行" + e.name + "操作？";
        //
        if (e.name == '发送核对申请') {
          title = "发送核对申请时，请确认当前变更低保家庭数据准确性（包括身份证和核对授权书），" +
              "发送核对后，不允许调整低保变更的家庭户主信息、家庭成员信息（含非保障成员）、家庭赡（抚、扶）养人或家属信息（变更数据被核对系统驳回情况除外）";
        }
        this.$Modal.confirm({
          title: "操作确认",
          content: title,
          onOk: () => {
            that.$nextTick(() => {
                  var infor = that.$refs.handle.check(e.name);
                  if (infor) {
                    let btnName = e.name;
                    if (btnName.search("退回") == -1 && btnName.search("终止") == -1 && btnName.search("不同意迁出") == -1) {
                      //受理调整和审批初审环节信息可以编辑，需验证是否点击保存
                      if (this.handleNum == 0 || this.handleNum == 4) {
                        //停救、区内迁移、跨区迁移审批初审环不需编辑
                        if (this.familyInfo.ssca0016 != '300' &&
                            this.familyInfo.ssca0016 != '500' && this.familyInfo.ssca0016 != '501') {
                          if (!this.$refs.application.finishSave) {
                            this.$Message.error("请在第12步点击“保存”后再进行审批操作。");
                            return false;
                          }
                        }
                      }
                      // //maxl add 20210720
                      // // 流程审批控制，如果配置了要件必填校验，本阶段流程提交时需进行要件完整性校验，
                      // // 如果不满足条件，不允许审批提交
                      // if (that.validateCode == false) {
                      //   this.$Message.error(that.validateMsg);
                      //   return false;
                      // }
                      //校验必填要件
                      that.getApplication10Info(infor, e);
                    }else{
                      that.buzTaskComplete(infor, e);
                    }
                  }
                }
            );
          }
        })
      } else {
        this.$Message.error("下级审批人配置异常，请联系管理员！");
      }
    },

    buzTaskComplete(parmas, e) {
      parmas.acttaskid = this.familyInfo.acttaskid;
      parmas.processinstid = e.processinstid;
      parmas.taskid = e.taskid;
      parmas.status = e.status;
      parmas.opaction = e.name;
      if (e.varibles) {
        parmas.varibles = e.varibles;
      }
      parmas.ss12001Id = this.familyInfo.ss12001Id;
      parmas.processstage = this.familyInfo.processstage;
      if (e.ssca0012) {
        parmas.ssca0012 = e.ssca0012;
      }
      var that = this;
      that.Loading = true;
      that.btnLoading = true;
      postAction("/api/ac/subsistence/ss00000Service/createBuzTaskComplete", parmas).then((res) => {
        if (res.data.errcode == 0) {
          this.$emit('ok');
          this.visible = false;
        } else {
          this.$Message.error(res.data.errmsg);
        }
      }).finally(() => {
        that.Loading = false;
        that.btnLoading = false;
      });
    },
    cancel() {
      this.visible = false;
    },
    changeButton(e) {
      if (e == '0') {
        for (var i in this.buttonList) {
          var name = this.buttonList[i].name;
          if (name.search("退回") != -1 || name.search("终止") != -1) {
            this.buttonList[i].disable = '0';
          } else if (this.buttonList[i].name.search("非救助") != -1) {
            this.buttonList[i].disable = '0';
          } else if (this.buttonList[i].name.search("不予救助") != -1) {
            this.buttonList[i].disable = '0';
          } else {
            this.buttonList[i].disable = '1';
          }
        }
      } else {
        this.buttonList = JSON.parse(JSON.stringify(this.oldButtonList));
      }
    },
    //设置所有审批按钮无法点击
    lockAllButton(e) {
      if (e) {
        for (var i in this.buttonList) {
          this.buttonList[i].disable = '1';
        }
      } else {
        this.buttonList = this.oldButtonList;
      }
    },
    //隐藏审批按钮
    setButtonHidden(e) {
      if (e) {
        this.buttonHidden = "display:none";
      } else {
        this.buttonHidden = "display:block";
      }
    }
  },
  created() {
    // this.height = document.documentElement.clientHeight - 250;
    //this.btnLoading=false
  }
}
</script>

<style scoped>
#Tab {
  height: 100%;
}

/deep/ .ivu-tabs-content {
  height: calc(100% - 50px);
  position: relative;
}

#inforDiv {
  width: 100%;
  position: relative;
  margin-top: 20px;
  min-height: 200px;
}

#examinationButtonDiv {
  position: absolute;
  bottom: 10px;
  width: 100%;
  text-align: center;
}

.overflowContent {
  position: absolute;
  width: 100%;
  overflow-y: auto;
  height: calc(100% - 60px);
}

/deep/ .ivu-modal-body {
  padding-top: 0px;
}

/deep/ .ivu-modal-footer {
  border-top: 0px;
  padding: 0px;
}
</style>
